<layout-header></layout-header>

<nav class="container-xl mb-3">
    <ol class="breadcrumb">
        <li class="breadcrumb-item"><a routerLink="/welcome">首页</a></li>
        <li class="breadcrumb-item"><a routerLink="/profile/list">用户配置</a></li>
        <li class="breadcrumb-item active">添加</li>
    </ol>
</nav>

<div class="container-xl mb-3">
    <form class="row gy-3" (ngSubmit)="createProfile()" #myform="ngForm">
        <div class="col-12">
            <label class="form-label">场景 *</label>
            <select name="roomid" class="form-select" [(ngModel)]="formdata.roomid" (change)="changeConacts()" required>
                <option value="-">私聊</option>
                @for (item of wcfChatrooms; track item.wxid) {
                <option [value]="item.wxid">{{item.name}}</option>
                }
            </select>
            <div class="form-text">
                用户配置所属场景，暂用作生效范围
            </div>
        </div>
        <div class="col-12">
            <label class="form-label">用户 *</label>
            <div class="row g-3">
                <div class="col col-md-8">
                    <select name="wxid" class="form-select" [(ngModel)]="formdata.wxid" [disabled]="conacts.length == 0" required>
                        @if (conactsFilter.length > 0) {
                        <option>选择筛选结果</option>
                        }
                        @for (item of conacts | filter:'wxid,name':conactsFilter; track item.wxid) {
                        <option [value]="item.wxid">{{item.wxid}}（{{item.name}}）</option>
                        }
                    </select>
                </div>
                <div class="d-none d-md-block col-md-4">
                    <input type="text" class="form-control" placeholder="过滤条件" [(ngModel)]="conactsFilter" [disabled]="conacts.length == 0" />
                </div>
            </div>
            <div class="form-text">
                关联的用户，非好友无法添加私聊配置
            </div>
        </div>
        <div class="col-12">
            <label class="form-label">级别</label>
            <select name="level" class="form-select" [(ngModel)]="formdata.level">
                @for (item of userLevels | keyvalue; track item.key) {
                <option [value]="item.key">{{item.value.name}}</option>
                }
            </select>
            <div class="form-text">
                用于适配机器人使用权限
            </div>
        </div>
        <div class="col-12">
            <label class="form-label">AI 模型</label>
            <select name="ai_model" class="form-select" [(ngModel)]="formdata.ai_model">
                @for (item of llmodels; track item.rd) {
                <option [value]="item.mid">{{item.mid}}（{{item.provider}}:{{item.model}}）</option>
                }
            </select>
            <div class="form-text">
                用户指定使用的 AI 模型
            </div>
        </div>
        <div class="col-12">
            <label class="form-label">备注</label>
            <input type="text" name="remark" class="form-control" [(ngModel)]="formdata.remark" />
            <div class="form-text">
                备注信息
            </div>
        </div>
        <div class="col-12">
            <button type="submit" class="btn btn-primary" [disabled]="myform.invalid">确认</button>
        </div>
    </form>
</div>